package com.six.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.six.bean.Supplying;
import com.six.service.SupplyingService;
import com.six.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("supplying")
@CrossOrigin
public class SupplyingController {
    //依赖注入
    @Autowired
    SupplyingService supplyingService;

    //    @RequestMapping("list")
//    public List<Admin> getlist1(){
//        List<Admin> list=adminService.list();
//        return list;
//    }
    @GetMapping("list")
    public Result getList(){
        List<Supplying> list = supplyingService.list();
        return Result.success(list);
    }

    @GetMapping("page")
    public Result getPage(Page page){
        Page result=supplyingService.page(page);
        return Result.success(result);
    }
    @PostMapping
    public Result add(@RequestBody Supplying supply){
        supplyingService.save(supply);
        Supplying supply1=supplyingService.getById(supply.getSid());
        return Result.success("保存成功",supply1);
    }
    @DeleteMapping("/{sid}")
    public Result delete(@PathVariable("sid") Integer sid){
        boolean b = supplyingService.removeById(sid);
        if(b){
            return Result.success("删除成功");
        }else {
            return Result.fail(201,"删除失败");
        }
    }
    @PutMapping
    public Result edit(@RequestBody Supplying supply){
        boolean b = supplyingService.saveOrUpdate(supply);
        Supplying supply1=supplyingService.getById(supply.getSid());
        if(b){
            return Result.success("保存成功",supply1);
        }else {
            return Result.fail(201,"修改失败");
        }
    }

}
